package com.summba.corpus.extractor;

import java.io.BufferedReader;
import java.io.File;
import java.util.Iterator;
import java.util.List;

import com.summba.common.Common;

public class ApacheLogExtractor {
	//private BufferedReader fileBuffferdReader;
	private List<String> fileLineList;
	private String resFilePath;
	
	public ApacheLogExtractor(String filePath, String saveFile){
		resFilePath = saveFile;
		File file = new File(filePath);
		if( !file.exists() ){
			System.out.println("Error|the file("+filePath+") is not exists!");
			System.exit(0);
		}
		BufferedReader fileBuffferdReader = Common.getFileInfo(filePath);
		fileLineList =  Common.bufferedReaderToList(fileBuffferdReader);
	}
	
	public void getMatchLine(String matchString){
		for (Iterator<String> iterator = fileLineList.iterator(); iterator.hasNext();) {
			String lineContent = (String) iterator.next();
			if( lineContent.indexOf(matchString,0) != -1 ){
				Common.appendFile(resFilePath, lineContent+"\n");
			}
		}
	}
	
	public void analysisString(){
		BufferedReader fileBuffferdReader = Common.getFileInfo(resFilePath);
		List<String> saveFileLineList =  Common.bufferedReaderToList(fileBuffferdReader);
		int i = 0;
		int j = 0;
		for (Iterator<String> iterator = saveFileLineList.iterator(); iterator.hasNext();) {
			String lineContent = (String) iterator.next();
			String[] temp = lineContent.split(" ");
			if( temp.length > 10){
				if( temp[10].indexOf("http://weibo.com/") != -1 ){
					i++;
					System.out.println("i is "+i);
				}
				j++;
				System.out.println("j is "+j);
			}
		}
	}

}
